#include <REGX52.H>
#include "Delay.h"

/**
   * @brief  获取独立按键键码
   * @param  无
   * @retval 按键的键码，范围0~4，无按键按下时返回0
   */

unsigned char Key_KeyNumber;

unsigned char Key()
{
    unsigned char Temp=0;
    Temp=Key_KeyNumber;
    Key_KeyNumber=0;
    return Temp;
}

unsigned char Key_GetState()
{
    unsigned char keynum=0;
	if(P3_1==0){keynum=1;}
	if(P3_0==0){keynum=2;}
	if(P3_2==0){keynum=3;}
	if(P3_3==0){keynum=4;}
	return keynum;
}

unsigned char Key_Loop()
{
    static unsigned char NowState,LastState;
    LastState=NowState;
    NowState=Key_GetState();
    if(LastState==1&&NowState==0)
    {
        Key_KeyNumber=1;
    }
    if(LastState==2&&NowState==0)
    {
        Key_KeyNumber=2;
    }
    if(LastState==3&&NowState==0)
    {
        Key_KeyNumber=3;
    }
    if(LastState==4&&NowState==0)
    {
        Key_KeyNumber=4;
    }
}